package com.yanqu.road.server.cmd.newmonopolymkt;

import com.yanqu.road.entity.enums.eMailType;
import com.yanqu.road.entity.player.UserInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.newmonopolymkt.NewMonopolyMarketProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.logic.mail.MailManager;
import com.yanqu.road.server.manger.MultipleLanguageMgr;
import com.yanqu.road.server.manger.player.UserMgr;
import com.yanqu.road.server.manger.systemgroup.newmonopolymarket.NewMonopolyMarketMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_NEW_MONOPOLY_MARKET_SEND_RES_GRAB_RANK_REWARD_FROM_CROSS, desc = "跨服自动发奖(资源点)")
public class NewMonopolyMarketSendResGrabRewardCmdFromCross implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        NewMonopolyMarketProto.NewMonopolyMarketSendResGrabRewardSync sync = NewMonopolyMarketProto.NewMonopolyMarketSendResGrabRewardSync.parseFrom(yanQuMessage.getBytes());
        UserInfo userInfo = UserMgr.getUserInfo(sync.getUserId());
        if(userInfo == null){
            return;
        }
        String language = userInfo.getLanguage();
        String mailTitle = MultipleLanguageMgr.getContent(MailManager.NEWMONOPOLY_MARKET_END_REWARD_TITLE, language);
        String mailContent = MultipleLanguageMgr.getContent(MailManager.NEWMONOPOLY_MARKET_END_REWARD_CONTENT, language);
        MailManager.sendMail(userInfo.getUserId(), eMailType.SYSTEM.getValue(), sync.getReward(), mailContent, mailTitle);
        NewMonopolyMarketMgr.getLogger().info("new monopoly send resGrab reward userId {}, reward {}", userInfo.getUserId(), sync.getReward());
    }
}
